package com.training.web.controller.comtent;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.training.common.annotation.Log;
import com.training.common.core.controller.BaseController;
import com.training.common.core.domain.AjaxResult;
import com.training.common.enums.BusinessType;
import com.training.content.domain.AssessItem;
import com.training.content.service.IAssessItemService;
import com.training.common.utils.poi.ExcelUtil;
import com.training.common.core.page.TableDataInfo;

/**
 * 考核内容Controller
 * 
 * @author training
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/assess/item")
public class AssessItemController extends BaseController
{
    @Autowired
    private IAssessItemService assessItemService;

    /**
     * 查询考核内容列表
     */
    @PreAuthorize("@ss.hasPermi('assess:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssessItem assessItem)
    {
        startPage();
        List<AssessItem> list = assessItemService.selectAssessItemList(assessItem);
        return getDataTable(list);
    }

    /**
     * 导出考核内容列表
     */
    @PreAuthorize("@ss.hasPermi('assess:item:export')")
    @Log(title = "考核内容", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AssessItem assessItem)
    {
        List<AssessItem> list = assessItemService.selectAssessItemList(assessItem);
        ExcelUtil<AssessItem> util = new ExcelUtil<AssessItem>(AssessItem.class);
        return util.exportExcel(list, "考核内容数据");
    }

    /**
     * 获取考核内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('assess:item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return AjaxResult.success(assessItemService.selectAssessItemByItemId(itemId));
    }

    /**
     * 新增考核内容
     */
    @PreAuthorize("@ss.hasPermi('assess:item:add')")
    @Log(title = "考核内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssessItem assessItem)
    {
        return toAjax(assessItemService.insertAssessItem(assessItem));
    }

    /**
     * 修改考核内容
     */
    @PreAuthorize("@ss.hasPermi('assess:item:edit')")
    @Log(title = "考核内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssessItem assessItem)
    {
        return toAjax(assessItemService.updateAssessItem(assessItem));
    }

    /**
     * 删除考核内容
     */
    @PreAuthorize("@ss.hasPermi('assess:item:remove')")
    @Log(title = "考核内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(assessItemService.deleteAssessItemByItemIds(itemIds));
    }
}
